package com.jwdf.uda.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Build;
import android.os.Bundle;
import android.widget.LinearLayout;

import com.jwdf.uda.R;
import com.jwdf.uda.databinding.ActivityContentBinding;
import com.jwdf.uda.ui.fragment.base.BaseFragment;
import com.jwdf.uda.ui.fragment.user.personal.StylistInfoFragment;
import com.jwdf.uda.ui.fragment.user.personal.UserInfoFragment;
import com.jwdf.uda.utils.DisplayUtils;

/**
 * Created by Administrator on 2016/6/2.
 */
public class UserInfoActivity extends AbsActivity {
    private ActivityContentBinding mDataBinding;

    public static void start(Context context, String uid, boolean isDesigner) {
        Intent intent = new Intent(context, UserInfoActivity.class);
        intent.putExtra("uid", uid);
        intent.putExtra("designer", isDesigner);
        context.startActivity(intent);
    }

    public static void start(Context context, String uid, String style, boolean isDesigner) {
        Intent intent = new Intent(context, UserInfoActivity.class);
        intent.putExtra("uid", uid);
        intent.putExtra("style", style);
        intent.putExtra("designer", isDesigner);
        context.startActivity(intent);
    }

    @Override
    protected boolean fullScreenMode() {
        return true;
    }

    private BaseFragment onCreateContentFragment() {
        boolean isDesigner = getIntent().getBooleanExtra("designer", false);
        return isDesigner ? new StylistInfoFragment() : new UserInfoFragment();
    }

    private Bundle onPutArguments() {
        Bundle args = new Bundle();
        args.putString("uid", getIntent().getStringExtra("uid"));
        args.putString("style", getIntent().getStringExtra("style"));
        return args;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mDataBinding = DataBindingUtil.setContentView(this, R.layout.activity_content);
        BaseFragment contentFragment = onCreateContentFragment();
        contentFragment.setArguments(onPutArguments());
        getSupportFragmentManager()
                .beginTransaction()
                .replace(R.id.fl_content, contentFragment, null).commitAllowingStateLoss();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mDataBinding.flContent.getLayoutParams();
            lp.topMargin -= DisplayUtils.getStatusBarHeight(this);
            mDataBinding.flContent.setLayoutParams(lp);
        }
    }

}
